package com.example.customer.serviceImpl;

import com.example.customer.dao.CusInfoDAO;
import com.example.customer.entity.Contact;
import com.example.customer.entity.CusInfo;
import com.example.customer.entity.Customer;
import com.example.customer.service.CusInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service("CusInfoServiceImpl")
public class CusInfoServiceImpl implements CusInfoService {

    @Autowired
    CusInfoDAO cusInfoDAO;

    @Override
    public PageInfo<Customer> queryCustomer(int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Customer> list =  cusInfoDAO.queryDataAll();
        PageInfo<Customer> dataList  =  new PageInfo<Customer>(list);
        return dataList;
    }

    @Override
    public PageInfo<Customer> queryCondition(Customer customer, int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Customer> list =  cusInfoDAO.queryCondition(customer);
        PageInfo<Customer> dataList  =  new PageInfo<Customer>(list);
        return dataList;
    }

    @Override
    public PageInfo<Customer> queryLost(Customer customer, int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Customer> list =  cusInfoDAO.queryLost(customer);
        PageInfo<Customer> dataList  =  new PageInfo<Customer>(list);
        return dataList;
    }

    @Override
    public PageInfo<Contact> queryByCID(String cus_id, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Contact> list =  cusInfoDAO.queryByCID(cus_id);
        PageInfo<Contact> dataList  =  new PageInfo<Contact>(list);
        return dataList;
    }

    @Override
    public Contact queryById(String id) {
        Contact data  =  cusInfoDAO.queryById(id);
        return data;
    }

    @Override
    public List<Map> queryInfo(String cus_id) {
        List<Map> list = cusInfoDAO.queryInfo(cus_id);
        return list;
    }

    @Override
    public CusInfo queryCusInfo(CusInfo cusInfo) {
        CusInfo data = cusInfoDAO.queryCusInfo(cusInfo);
        return data;
    }

    @Override
    @Transactional
    public void saveCusInfo(CusInfo cusInfo) {
        cusInfoDAO.saveCusInfo(cusInfo);
    }

    @Override
    @Transactional
    public void modify(Contact contact) {
        cusInfoDAO.modify(contact);
    }

    @Override
    @Transactional
    public void updStatus(String id, String status) {
        cusInfoDAO.updStatus( id, status);
    }

    @Override
    @Transactional
    public void updCustomer(Customer customer) {
        cusInfoDAO.updCustomer(customer);
    }

    @Override
    @Transactional
    public void updCusInfo(CusInfo cusInfo) {
        cusInfoDAO.updCusInfo(cusInfo);
    }

    @Override
    @Transactional
    public void delInfo(String id) {
        cusInfoDAO.delInfo(id);
    }

    @Override
    @Transactional
    public void delContact(String id) {
        cusInfoDAO.delContact(id);
    }
}
